package com.sjh.lib_app.adapter

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter

/**
 *@author : created by SunJH
 *时间：2021/8/6 000614
 *作用：viewPage的简单适配器
 */
class QuickPagerAdapter<T : View>(private val mList: ArrayList<T>) : PagerAdapter() {

    override fun getCount(): Int {
        return mList.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        container.addView(mList[position])
        return mList[position]
    }

    fun addPage(pageView: T) {
        mList.add(pageView)
        notifyDataSetChanged()
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as T)
    }

    fun getNowShowData(position: Int): T = mList[position]

}